package 链表;

/**
 * @ClassName : _860_柠檬水找零
 * @Author : 骆发茂
 * @Date: 2021/12/13 13:15
 * @Description : https://leetcode-cn.com/problems/lemonade-change/
 */
public class _860_柠檬水找零 {
    class Solution {
        public boolean lemonadeChange(int[] bills) {
            int five = 0;
            int ten = 0;
            for (int bill : bills){
                if(bill == 5){
                    five ++;
                }
                else if(bill ==10){
                    if(five==0){
                        return false;
                    }
                    five--;
                    ten++;
                }
                else{
                    if(five>0&&ten>0){
                        five--;
                        ten--;
                    }
                    else if(five>=3){
                        five -= 3;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            return true;
        }
    }
}